package com.sedu.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sedu.common.annotation.Log;
import com.sedu.common.core.controller.BaseController;
import com.sedu.common.core.domain.AjaxResult;
import com.sedu.common.enums.BusinessType;
import com.sedu.manage.domain.Subject;
import com.sedu.manage.service.ISubjectService;
import com.sedu.common.utils.poi.ExcelUtil;
import com.sedu.common.core.page.TableDataInfo;

/**
 * 学科管理Controller
 *
 * @author yulinfeng
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/manage/subject")
public class SubjectController extends BaseController {
    @Autowired
    private ISubjectService subjectService;

    /**
     * 查询学科管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(Subject subject) {
        startPage();
        List<Subject> list = subjectService.selectSubjectList(subject);
        return getDataTable(list);
    }

    // 查询所有学科
    @PreAuthorize("@ss.hasPermi('manage:subject:list')")
    @GetMapping("/all")
    public AjaxResult all() {
        List<Subject> list = subjectService.selectSubjectList(new Subject());
        return success(list);
    }

    /**
     * 导出学科管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:subject:export')")
    @Log(title = "学科管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Subject subject) {
        List<Subject> list = subjectService.selectSubjectList(subject);
        ExcelUtil<Subject> util = new ExcelUtil<Subject>(Subject.class);
        util.exportExcel(response, list, "学科管理数据");
    }

    /**
     * 获取学科管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:subject:query')")
    @GetMapping(value = "/{subjectId}")
    public AjaxResult getInfo(@PathVariable("subjectId") Long subjectId) {
        return success(subjectService.selectSubjectBySubjectId(subjectId));
    }

    /**
     * 新增学科管理
     */
    @PreAuthorize("@ss.hasPermi('manage:subject:add')")
    @Log(title = "学科管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subject subject) {
        return toAjax(subjectService.insertSubject(subject));
    }

    /**
     * 修改学科管理
     */
    @PreAuthorize("@ss.hasPermi('manage:subject:edit')")
    @Log(title = "学科管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subject subject) {
        return toAjax(subjectService.updateSubject(subject));
    }

    /**
     * 删除学科管理
     */
    @PreAuthorize("@ss.hasPermi('manage:subject:remove')")
    @Log(title = "学科管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{subjectIds}")
    public AjaxResult remove(@PathVariable Long[] subjectIds) {
        return toAjax(subjectService.deleteSubjectBySubjectIds(subjectIds));
    }
}
